<?php

!defined('IN_FENGTOP') && exit('Access Denied');
 
class control extends base{
	private $WikiLastest;
	private $ForumLastest;
	
	function control(& $get,& $post){
		$this->base( & $get,& $post);
		//$this->load('category');
	}

	function dodefault() {
		$getForumSQL = "SELECT * 
		                  FROM  `".DBforum_TABLEPRE."post` 
		                 WHERE  `first` =1
		              ORDER BY  `dateline` DESC ";
		$this->ForumLastest   = $this->db->get_array($getForumSQL);
//print_r($this->ForumLastest);
		$getWikiSQL = "SELECT * 
		                 FROM  `".DBwiki_TABLEPRE."doc` 
		                WHERE  `cid` =0
		             ORDER BY  `lastedit` DESC ";
		$this->WikiLastest   = $this->db->get_array($getWikiSQL);

		$this->writeSitemapHtml();
echo 'OK';
		$this->writeSitemapXML();
	}

	function writeSitemapHtml(){
		$file_name = "../sitemap.html"; 
	// 绝对路径: homedata.dat 

	$file_pointer = fopen($file_name, "w"); 
	// "w"是一种模式，8.    详见后面

		fwrite($file_pointer, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>网站地图- 魔方 - 科技改变生活！</title>
<meta http-equiv="Content-type" content="text/html;" charset="UTF-8" />
<style type="text/css">
<!-- 
 .STYLE1 {
 font-size: 12px;
 color: #333333;
 }
 -->
 </style>
</head>
 <body>
 <table align="center">
 <tr  align="center">
 <td align="center">
 <table width="766" border="0" >
 <tr align="left">
 <td class="STYLE1" ><span >网站地图(Build090324)：('.date("Y-m-d H:i:s").')</span></td>
 </tr>
   <tr align="left"> 
 <td width="760" class="STYLE1">1.&nbsp;<a href="http://magicube.ws/magicube/"> 魔方 - 魔方 - 科技改变生活！</a></td>
</tr>	');
		
		//循环写入forum
		$count = count($this->ForumLastest);
		for($i = 0; $i < $count; $i++){
			fwrite($file_pointer, '<tr align="left"> <td width="760" class="STYLE1">'.($i + 2).'.&nbsp;<a href="http://magicube.ws/forum/index.php?doc-view-'.$this->ForumLastest[$i]['pid'].'">'.$this->ForumLastest[$i]['subject'].'</a></td></tr>'); 
		}
		//循环写入wiki
		$count = count($this->WikiLastest);
		for($i = 0; $i < $count; $i++){
			fwrite($file_pointer, '<tr align="left"> <td width="760" class="STYLE1">'.($i + 1).'.&nbsp;<a href="http://magicube.ws/wiki/index.php?doc-view-'.$this->WikiLastest[$i]['did'].'">'.$this->WikiLastest[$i]['title'].'</a></td></tr>'); 
		}
		fwrite($file_pointer, '</table> </td> </tr> </table><br />
<br />
<br />
<br />
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/>
<!--
PLEASE NOTE!
You are NOT allowed to remove and/or modify the copyright notice below.
Thank you! Build090324
-->
<table width=940><tr align="right"><td align="right" class="STYLE1">by <a target="_blank" href="http://www.sitemap-xml.org">www.sitemap-xml.org</a> </td></tr></table>
 </body> </html>'); 
		// 先把文件剪切12.    为0字节大小，13.     然后写入
 
		fclose($file_pointer); 
		// 结束
 
		print "数据成功写入文件"; 
	}
	
	function writeSitemapXML(){
		$file_name = "../sitemap.xml"; 
	// 绝对路径: homedata.dat 

	$file_pointer = fopen($file_name, "w"); 
	// "w"是一种模式，8.    详见后面

		fwrite($file_pointer, '<?xml version="1.0" encoding="utf-8"?>
<urlset
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
       http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">');
		
		//循环写入forum
		$count = count($this->ForumLastest);
		for($i = 0; $i < $count; $i++){
			fwrite($file_pointer, '<url>
<loc>http://magicube.ws/forum/index.php?doc-view-'.$this->ForumLastest[$i]['pid'].'</loc>
<priority>1.00</priority>
<lastmod>'.date("Y-m-d").'</lastmod>
<changefreq>always</changefreq>
</url>
'); 
		}
		//循环写入wiki
		$count = count($this->WikiLastest);
		for($i = 0; $i < $count; $i++){
			fwrite($file_pointer, '<url>
<loc>http://magicube.ws/wiki/index.php?doc-view-'.$this->WikiLastest[$i]['did'].'</loc>
<priority>1.00</priority>
<lastmod>'.date("Y-m-d").'</lastmod>
<changefreq>always</changefreq>
</url>
'); 
		}
		fwrite($file_pointer, '</urlset>'); 
		// 先把文件剪切12.    为0字节大小，13.     然后写入
 
		fclose($file_pointer); 
		// 结束
 
		print "数据成功写入文件"; 
	}
}
?>
